﻿using StudentManage.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentManage.ViewModels.Base
{
    /// <summary>
    /// ViewModel基类  实现INotifyPropertyChanged接口
    /// </summary>
    public class ViewModelBase : INotifyPropertyChanged
    {
        /// <summary>
        /// 属性值更改通知客户端事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// 执行属性值更改事件
        /// [CallerMemberName]特性-允许获取调用方的方法或属性名
        /// 解决调用方法时不需要传入属性名
        /// </summary>
        /// <param name="proName">属性名</param>
        protected void OnPropertyChanged([CallerMemberName] string proName = "")
        {
            // 执行属性值更改事件
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(proName));
        }

        #region 弹窗相关
        /// <summary>
        /// 显示窗口的方法
        /// </summary>
        /// <param name="key"></param>
        /// <param name="vm"></param>
        public void Show(string key, object vm)
        {
            WindowManager.Show(key, vm);
        }

        /// <summary>
        /// 显示窗口的方法 ShowDialog
        /// </summary>
        /// <param name="key"></param>
        /// <param name="vm"></param>
        public void ShowDialog(string key, object vm)
        {
            WindowManager.ShowDialog(key, vm);
        }

        /// <summary>
        /// 关闭弹窗
        /// </summary>
        /// <param name="win"></param>
        public void Close(object win)
        {
            WindowManager.Close(win);
        }
        #endregion

        #region 消息提示框
        /// <summary>
        /// 询问消息框
        /// </summary>
        /// <param name="title"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public MessageBoxResult ShowQuestion(string title, string msg)
        {
            return MessageBox.Show(msg, title, MessageBoxButton.YesNo, MessageBoxImage.Question);
        }
        /// <summary>
        /// 成功消息提示
        /// </summary>
        /// <param name="title"></param>
        /// <param name="msg"></param>
        public void ShowInfo(string title, string msg)
        {
            MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Information);
        }
        /// <summary>
        /// 错误消息提示
        /// </summary>
        /// <param name="title"></param>
        /// <param name="msg"></param>
        public void ShowError(string title, string msg)
        {
            MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Error);
        }
        #endregion
    }
}
